package Simple;

import java.util.*;
import java.io.*;

/**
 * Input as aaabbbcc, show output as a3b3c2
 * 
 * @author CY
 * 
 */
public class numberofchar {

	private TreeMap<Character, Integer> map = new TreeMap<Character, Integer>();
	private char[] ch;
	private int n;
	private Iterator<Character> wordIterator;

	public numberofchar() {
		this.ch = read();
		this.n = ch.length;
		this.map = toMap(ch);
		this.wordIterator = map.keySet().iterator();
	}

	public static char[] read() {
		System.out.println("Input a string");
		Scanner in = new Scanner(System.in);
		String s = in.nextLine();
		char[] charArray = s.toCharArray();
		return charArray;
	}

	public static TreeMap<Character, Integer> toMap(char[] my_ch) {
		TreeMap<Character, Integer> wordmap = new TreeMap<Character, Integer>();

		for (int i = 0; i < my_ch.length; i++) {
			if (!wordmap.containsKey(my_ch[i])) {
				wordmap.put(my_ch[i], 1);
			} else {
				int count = wordmap.get(my_ch[i]);
				count++;
				wordmap.put(my_ch[i], count);
			}
		}
		return wordmap;
	}

	public static void main(String args[]) {
		numberofchar test = new numberofchar();
		Iterator<Character> i = test.wordIterator;
		TreeMap<Character, Integer> my_map = test.map;

		while (i.hasNext()) {

			char temp = i.next();

			System.out.print(temp + "" + my_map.get(temp));
		}

	}
}
